package com.cuz.daileetcode;

import com.cuz.daileetcode.utils.TreeNode;

import java.util.ArrayList;
import java.util.Scanner;

public class Day24_3 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //后序
        String prefix = scanner.nextLine();
        //中序
        String mid = scanner.nextLine();
        char[] prefixChar = prefix.toCharArray();
        int pLen = prefixChar.length;
        char[] midChar = prefix.toCharArray();
        int mLen = midChar.length;
        char rootChar = prefixChar[pLen - 1];
        TreeNode root = new TreeNode(rootChar);
        char[][] lRSon = subTree(midChar, rootChar);
        char[][] lrPrfix = treeInMid(prefixChar, lRSon[0], lRSon[1]);
    }

    public static char[][] subTree(char[] midChar, char root) {
        ArrayList<Character> leftTree = new ArrayList<>();
        ArrayList<Character> rightTree = new ArrayList<>();
        boolean isMeedRoot = false;
        for (char c : midChar) {
            if (c == root) {
                isMeedRoot = true;
                continue;
            }
            if (!isMeedRoot) {
                leftTree.add(c);
            } else {
                rightTree.add(c);
            }
        }
        char[] leftCharArray = new char[leftTree.size()];
        char[] rightCharArray = new char[rightTree.size()];
        for (int index = 0; index < leftTree.size(); index++) {
            leftCharArray[index] = leftTree.get(index);
        }
        for (int index = 0; index < leftTree.size(); index++) {
            rightCharArray[index] = rightTree.get(index);
        }
        return new char[][]{leftCharArray, rightCharArray};
    }

    public static char[][] treeInMid(char[] prefixChar, char[] leftCharArray, char[] rightCharArray) {
        ArrayList<Character> leftTreeInMid = new ArrayList<>();
        ArrayList<Character> rightTreeInMid = new ArrayList<>();
        for (char p : prefixChar) {
            for (char l : leftCharArray) {
                if (l==p){
                    leftTreeInMid.add(p);
                }
            }
            for (char r : rightCharArray) {
                if (r==p){
                    rightTreeInMid.add(p);
                }
            }
        }

        char[] leftCharArray2 = new char[leftTreeInMid.size()];
        char[] rightCharArray2 = new char[rightTreeInMid.size()];
        for (int index = 0; index < leftTreeInMid.size(); index++) {
            leftCharArray[index] = leftTreeInMid.get(index);
        }
        for (int index = 0; index < rightTreeInMid.size(); index++) {
            rightCharArray[index] = rightTreeInMid.get(index);
        }
        return new char[][]{leftCharArray2, rightCharArray2};
    }

}
